import jsonlines
import json
from tqdm import tqdm
datas = []
with open("ultrachat_700k.jsonl") as f:
    for li, line in tqdm(enumerate(f)):
        try:
            line = json.loads(line)
        except:
            continue
        convs = []
        for ci, conv in enumerate(line["data"]):
            if ci % 2 == 0:
                convs.append({"from":"human","value":conv})
            else:
                convs.append({"from":"gpt","value":conv})
        datas.append({"id":f"ultrachat_{ci}","conversations":convs})

with jsonlines.open("ultrachat_700k_fastchat.jsonl","w") as wf:
    for d in tqdm(datas):
        wf.write(d)
